package cn.springcloud.fix.auth.service;

import cn.springcloud.fix.auth.service.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.stream.Stream;

@Slf4j
@Service
public class AuthServiceImpl implements AuthService {

    @Value("${auth.ignore.urls}")
    private String ignoreUrls = "/oauth";

    /**
     * authentication是否失效
     */
    @Override
    public boolean invalidJwtAccessToken(String authentication) {
        return false;
    }

    @Override
    public boolean hasPermission(String authentication, String url, String method) {
        if (invalidJwtAccessToken(authentication)) {
            return false;
        }
        return true;
        // return hasPermission(authenticate(authentication, url, method));
    }

    @Override
    public boolean ignoreAuthentication(String url) {
        return Stream.of(ignoreUrls.split(",")).anyMatch(ignoreUrl -> url.startsWith(StringUtils.trim(ignoreUrl)));
    }
}
